package com.ksd.modules.special.controller;

import com.ksd.common.annotation.ApiLog;
import com.ksd.common.controller.BaseController;
import com.ksd.common.core.result.R;
import com.ksd.common.web.annotation.RepeatSubmit;
import com.ksd.modules.special.po.AdminSpecialBindDetailSavePO;
import com.ksd.modules.special.service.IAdminSpecialBindDetailService;
import com.ksd.modules.special.vo.AdminSpecialBindDetailVo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
public class AdminSpecialBindDetailController extends BaseController {
    
    @Autowired
    private IAdminSpecialBindDetailService adminSpecialBindDetailService;

    /**
     * 【专题绑定】 - 保存和更新
     * @param adminSpecialBindDetailSavePO
     * @return
     */
    @PostMapping("/special/bind/detail/saveupdate")
    @ApiLog("【专题绑定】 - 保存和更新")
    @RepeatSubmit
    public R<Boolean> saveUpdateAdminSpecialBindDetails(@Validated @RequestBody AdminSpecialBindDetailSavePO adminSpecialBindDetailSavePO){
        return R.data(adminSpecialBindDetailService.saveUpdateAdminSpecialBindDetail(adminSpecialBindDetailSavePO));
    }

    /**
     * 【专题绑定】 - 根据id查询明细
     * @param id
     * @return
     */
    @PostMapping("/special/bind/detail/get/{id}")
    public R<AdminSpecialBindDetailVo> getAdminSpecialBindDetailsById(@PathVariable("id")Long id){
        return R.data(adminSpecialBindDetailService.getAdminSpecialBindDetailById(id));
    }


    /**
     * 【专题绑定】- 根据ID恢复删除
     * @param id
     * @return
     */
    @PostMapping("/special/bind/detail/remove/{id}")
    @ApiLog("【专题绑定】- 根据ID恢复删除")
    public R<Boolean> removeAdminSpecialById(@PathVariable("id")Long id){
        return R.data(adminSpecialBindDetailService.removeAdminSpecialBindDetailById(id));
    }

    /**
     * 【专题绑定】- 修改状态
     *
     * @return
     */
    @PostMapping("/special/bind/detail/status/{id}/{field}")
    @ApiLog("【专题绑定】- 修改状态")
    @RepeatSubmit
    public R<Boolean> updateStatus(
            @PathVariable("id") Long id,
            @PathVariable("field") String field,
            @RequestParam("value") String value
    ) {
        if(StringUtils.isNumeric(value)) {
            return R.data(adminSpecialBindDetailService.updateStatus(id, field, Integer.parseInt(value)));
        }else{
            return R.data(adminSpecialBindDetailService.updateStatusStr(id, field, String.valueOf(value)));
        }
    }

    /**
     * 【专题绑定】 - 复制数据
     * @param opid
     * @return
     */
    @PostMapping("/special/bind/detail/copy/{opid}")
    @ApiLog("【专题绑定】 -复制数据")
    @RepeatSubmit
    public R<Boolean> copyData(@PathVariable("opid")Long opid){
        return R.data(adminSpecialBindDetailService.copyData(opid));
    }
}
